package algorithm;

public class leetcode_0739 {
    public int[] dailyTemperatures(int[] temperatures) {
        int len=temperatures.length;
        int[] dp=new int[len];
        int[] result=new int[len];
        int current=0;
        for(int i=0;i<len;++i){
            if(current==0||temperatures[i]<=temperatures[dp[current-1]]) {
                dp[current]=i;
                current++;
                continue;
            }

            while(current>=1&&temperatures[i]>temperatures[dp[current-1]]){
                result[dp[current-1]]=i-dp[current-1];
                current--;
            }
            dp[current]=i;
            current++;
        }
        return result;
    }
}
